"use strict";

function ZegoWebSocket(e, t) {
    if (this.url = e, this.protocol = t || null, this.readyState = 3, this._websocket = wx.connectSocket({
            url: e
        }), this._websocket) {
        this.readyState = 0;
        var s = this;
        this._websocket.onOpen(function (e) {
            s.readyState = s._websocket.readyState, "function" == typeof s.onopen && (s.onopen(), s._websocket.onClose(function (e) {
                s.readyState = s._websocket.readyState, "function" == typeof s.onclose && s.onclose(e)
            }), s._websocket.onMessage(function (e) {
                "function" == typeof s.onmessage && s.onmessage(e)
            }))
        }), this._websocket.onError(function (e) {
            s.readyState = s._websocket.readyState, "function" == typeof s.onerror && s.onerror(e)
        })
    }
}
ZegoWebSocket.prototype.onopen = function (e) {
}, ZegoWebSocket.prototype.onerror = function (e) {
}, ZegoWebSocket.prototype.onclose = function (e) {
}, ZegoWebSocket.prototype.onmessage = function (e) {
}, ZegoWebSocket.prototype.send = function (e) {
    this._websocket && this._websocket.send({
        data: e
    })
}, ZegoWebSocket.prototype.close = function () {
    this._websocket && this._websocket.close()
};
var ENUM_PLAY_STATE = {
    start: 0,
    playing: 1,
    stop: 2
};

function ZegoPlayer(e, t, s, r, o, i, a, n, l) {
    this.streamid = t,
    this.urls = s, 
    this.playUrlIndex = 0, 
    this.playUrlTryCount = 0, 
    this.currentUrl = null, 
    this.reconnectLimit = o, 
    this.reconnectCount = 0, 
    this.state = ENUM_PLAY_STATE.stop, 
    this.logger = e, 
    this.streamCenter = i, 
    this.sourceType = a, 
    this.playerType = n, 
    this.params = r, 
    this.playerSeq = 0, 
    this.publishQualitySeq = 0, 
    this.publishQualityCount = 0, 
    this.publishQulaityMaxCount = 10, 
    this.everSuccess = !1, 
    this.dataReport = l
}

function resetPlayer(e) {
    e.state = ENUM_PLAY_STATE.stop
}

function newPlayer(e) {
    resetPlayer(e);
    var t = e.getCurrentPlayerUrl(),
        s = t;
        0 != e.params.length && (s = t + "?" + e.params);
        t !== e.currentUrl 
            ? (e.currentUrl = t, e.streamCenter.onStreamUrlUpdate(e.streamid, s, e.playerType)) 
            : e.streamCenter.onPlayerRetry(e.streamid, e.playerType);
        0 == e.everSuccess  
            ? (0 == e.playerType 
                ? (e.dataReport.eventStart(e.playerSeq, "PlayBegin"), e.dataReport.addEventInfo(e.playerSeq, "PlayBegin", "url", s)) 
                : (e.dataReport.eventStart(e.playerSeq, "PublishBegin"), e.dataReport.addEventInfo(e.playerSeq, "PublishBegin", "url", s)))
            : (0 == e.playerType 
                ? e.dataReport.addEventInfo(e.playerSeq, "PlayRetry", "url", s) 
                : e.dataReport.eventStart(e.playerSeq, "PublishRetry", "url", s));
        e.state = ENUM_PLAY_STATE.start;
    return !0
}

function shouldRetryPlay(e, t) {
    var s = t.detail.code;
    return 3001 == s || 3002 == s || 3003 == s || 3005 == s
}

function isPlayFailed(e, t) {
    var s = t.detail.code;
    return -2301 == s || 2101 == s || 2102 == s
}

function shouldRetryPublish(e, t) {
    var s = t.detail.code;
    return 3001 == s || 3002 == s || 3003 == s || 3004 == s || 3005 == s
}

function isPublishFailed(e, t) {
    var s = t.detail.code;
    return -1301 == s || -1302 == s || -1303 == s || -1304 == s || -1305 == s || -1306 == s || -1307 == s || -1308 == s || -1309 == s || -1310 == s || -1311 == s
}

function reportQualityStatics(e) {
    e.dataReport.uploadReport(e.publishQualitySeq, "WXPublishStateUpdate"), e.publishQualityCount = 0, e.publishQualitySeq = 0
}


ZegoPlayer.prototype.stopPlayer = function () {
    0 == this.playerType 
        ? this.dataReport.eventEndWithMsg(this.playerSeq, "PlayStat", {quality: this.playerInfo}) 
        : (this.dataReport.addEventInfo(this.playerSeq, "PublishStat", "quality", this.playerInfo), this.dataReport.eventEndWithMsg(this.playerSeq, "PublishStat", {quality: this.playerInfo}))
}, ZegoPlayer.prototype.tryStartPlayer = function (e) {
    for (; this.playUrlTryCount < this.urls.length;)
        if (++this.reconnectCount > this.reconnectLimit) this.playUrlTryCount++, this.playUrlIndex = (this.playUrlIndex + 1) % this.urls.length, this.reconnectCount = 0;
        else if (this.logger.info("zp.tsp.0 index: " + this.playUrlIndex + ", url: " + this.getCurrentPlayerUrl()), newPlayer(this)) break;
    if (this.playUrlTryCount >= this.urls.length) {
        this.logger.info("zp.tsp.0 stream: " + this.streamid), resetPlayer(this);
        var t = "";
        0 == this.playerType ? t = "PlayEnd" : 1 == this.playerType && (t = "PublishEnd", reportQualityStatics(this));
        var s = {
            error: e,
            reason: "no url to retry"
        };
        this.dataReport.addEvent(this.playerSeq, t, s), this.streamCenter.onPlayerStop(this.streamid, this.playerType, e)
    }
}, ZegoPlayer.prototype.updateEvent = function (e) {
    if (0 == this.playerType) {
        if (2004 == e.detail.code) this.everSuccess ? this.dataReport.eventEnd(this.playerSeq, "PlayRetry") : (this.everSuccess = !0, this.dataReport.eventStart(this.playerSeq, "PlayStat")), this.streamCenter.onPlayerStart(this.streamid, this.playerType);
        else if (2009 == e.detail.code) this.streamCenter.onPlayerVideoSizeChanged(this.streamid);
        else if (shouldRetryPlay(this, e)) this.dataReport.eventStart(this.playerSeq, "PlayRetry"), this.dataReport.addEventInfo(this.playerSeq, "PlayRetry", "error_code", e.detail.code);
        else if (isPlayFailed(this, e)) {
            this.logger.info("zp.ue.0 play error: " + this.streamid), resetPlayer(this);
            var t = {
                errorCode: e.detail.code
            };
            this.dataReport.addEvent(this.playerSeq, "PlayError", t), this.streamCenter.onPlayerStop(this.streamid, this.playerType, e.detail.code)
        }
        this.everSuccess || this.dataReport.eventEnd(this.playerSeq, "PlayBegin")
    } else if (1 == this.playerType) {
        if (1002 == e.detail.code) this.everSuccess ? this.dataReport.eventEnd(this.playerSeq, "PublishRetry") : (this.everSuccess = !0, this.dataReport.eventStart(this.playerSeq, "PublishStat")), this.streamCenter.onPlayerStart(this.streamid, this.playerType);
        else if (shouldRetryPublish(this, e)) this.dataReport.eventStart(this.playerSeq, "PublishRetry"), this.dataReport.addEventInfo(this.playerSeq, "PublishRetry", "error_code", e.detail.code);
        else if (isPublishFailed(this, e)) {
            this.logger.info("zp.ue.0 publish error: " + this.streamid), resetPlayer(this);
            var s = {
                errorCode: e.detail.code
            };
            this.dataReport.addEvent(this.playerSeq, "PublishError", s), reportQualityStatics(this), this.streamCenter.onPlayerStop(this.streamid, this.playerType, e.detail.code)
        }
        this.everSuccess || this.dataReport.eventEnd(this.playerSeq, "PublishBegin")
    }
}, ZegoPlayer.prototype.updatePlayerNetStatus = function (e) {
    var t = {
        videoBitrate: e.detail.info.videoBitrate,
        audioBitrate: e.detail.info.audioBitrate,
        videoFPS: e.detail.info.videoFPS,
        videoHeight: e.detail.info.videoHeight,
        videoWidth: e.detail.info.videoWidth
    };
    if (this.playerInfo = t, 1 == this.playerType) {
        var s = {
            videoBitrate: e.detail.info.videoBitrate,
            audioBitrate: e.detail.info.audioBitrate,
            videoFPS: e.detail.info.videoFPS,
            videoGOP: e.detail.info.videoGOP,
            netSpeed: e.detail.info.netSpeed,
            netJitter: e.detail.info.netJitter,
            videoWidth: e.detail.info.videoWidth,
            videoHeight: e.detail.info.videoHeight
        };
        0 == this.publishQualitySeq && (this.publishQualitySeq = ++this.streamCenter.eventSeq, this.dataReport.newReport(this.publishQualitySeq)), this.dataReport.addEvent(this.publishQualitySeq, "PublishQuality", s), this.publishQualityCount += 1, this.publishQualityCount >= this.publishQulaityMaxCount && reportQualityStatics(this)
    }
    this.streamCenter.onPlayerQuality(this.streamid, t, this.playerType)
}, ZegoPlayer.prototype.getCurrentPlayerUrl = function () {
    return this.urls[this.playUrlIndex % this.urls.length]
} 

function ZegoDataReport(e) {
    this.logger = e, this.dataStatistics = {}
}

ZegoDataReport.prototype.newReport = function (e) {
    this.dataStatistics[e] = {
        abs_time: Date.now(),
        time_consumed: 0,
        error: 0,
        events: []
    }
}, ZegoDataReport.prototype.addMsgExt = function (e, t) {
    this.dataStatistics[e] && (this.dataStatistics[e].msg_ext = t)
}, ZegoDataReport.prototype.eventStart = function (e, t) {
    this.dataStatistics[e] 
        ? void 0 != this.dataStatistics[e].events 
            ? this.dataStatistics[e].events.push({
                event: t,
                abs_time: Date.now(),
                time_consumed: 0}) 
            : this.logger.info("zd.es.0 no events") 
        : this.logger.info("zd.es.0 no seq match")
}, ZegoDataReport.prototype.eventEnd = function (e, t) {
    if (this.dataStatistics[e]) {
        var s = this.dataStatistics[e].events;
        if (void 0 != s) {
            for (var r = s.length - 1; r >= 0; r--)
                if (s[r].event == t && void 0 != s[r].time_consumed) {
                    s[r].time_consumed = Date.now() - s[r].abs_time;
                    break
                }
        } else this.logger.info("zd.ee.0 no events")
    } else this.logger.info("zd.ee.0 no seq match")
}, ZegoDataReport.prototype.eventEndWithMsg = function (e, t, s) {
    if (this.dataStatistics[e]) {
        var r = this.dataStatistics[e].events;
        if (void 0 != r) {
            for (var o = r.length - 1; o >= 0; o--)
                if (r[o].event == t && void 0 != r[o].time_consumed) {
                    for (var i in r[o].time_consumed = Date.now() - r[o].abs_time, void 0 == r[o].msg_ext && (r[o].msg_ext = {}), s) r[o].msg_ext[i] = s[i];
                    break
                }
        } else this.logger.info("zd.ee.0 no events")
    } else this.logger.info("zd.ee.0 no seq match")
}, ZegoDataReport.prototype.addEventInfo = function (e, t, s, r) {
    if (this.dataStatistics[e]) {
        var o = this.dataStatistics[e].events;
        if (void 0 != o) {
            for (var i = o.length - 1; i >= 0; i--)
                if (o[i].event == t && void 0 != o[i].time_consumed && o[i].event == t && void 0 != o[i].time_consumed) {
                    void 0 == o[i].msg_ext && (o[i].msg_ext = {}), o[i].msg_ext[s] = r;
                    break
                }
        } else this.logger.info("zd.aei.0 no events")
    } else this.logger.info("zd.aei.0 no seq match")
}, ZegoDataReport.prototype.addEvent = function (e, t, s) {
    this.dataStatistics[e] ? void 0 != this.dataStatistics[e].events && (s ? this.dataStatistics[e].events.push({
        event: t,
        abs_time: Date.now(),
        msg_ext: s
    }) : this.dataStatistics[e].events.push({
        event: t,
        abs_time: Date.now()
    })) : this.logger.info("zd.ae.0 no seq match")
}, ZegoDataReport.prototype.uploadReport = function (e, t) {
    var s = this.dataStatistics[e];
    void 0 != s && (s.itemtype = t, s.time_consumed = Date.now() - s.abs_time, this.logger.report(s), delete this.dataStatistics[e])
};
var ENUM_PLAY_STATE_UPDATE = {
        start: 0,
        stop: 1,
        retry: 2
    },
    ENUM_PLAYER_TYPE = {
        play: 0,
        publish: 1
    };

function ZegoStreamCenter(e) {
    this.playerList = {}, 
    this.playerCount = 0, 
    this.logger = e, 
    this.playingList = [], 
    this.publishingList = [],
    this.dataReport = new ZegoDataReport(this.logger), 
    this.eventSeq = 0, 
    this.streamEventMap = {}
}

function updateStreamState(e, t, s, r) {
    if (void 0 != e)
        if (void 0 != s && "string" == typeof s || (s = ""), 1 == t) r.push({
            streamid: e,
            params: s
        });
        else
            for (var o = 0; o < r.length; o++)
                if (r[o].streamid == e) {
                    r.splice(o, 1);
                    break
                }
}

function startPlayer(e, t, s, r, o) {
    var i = e.playerList[t];
    if (i) return !0;
    var a = [];
    o == ENUM_PLAYER_TYPE.play ? a = e.playingList : o == ENUM_PLAYER_TYPE.publish && (a = e.publishingList);
    for (var n = !1, l = "", g = 0; g < a.length; g++)
        if (a[g].streamid == t) {
            n = !0, l = a[g].params;
            break
        }
    if (!n) return e.logger.warn("zpc.sp.0 should not start"), !1;
    if ((i = e.playerList[t] = new ZegoPlayer(e.logger, t, s, l, getReconnectLimit(e.dispatchType), e, r, o, e.dataReport)).playerSeq = e.streamEventMap[t], !i) return e.logger.info("zpc.sp.0 new player failed"), !1;
    ++e.playerCount;
    var d = i.tryStartPlayer(0);
    return e.logger.debug("zpc.sp.0 call result:", d), d
}

function stopPlayer(e, t) {
    var s = e.playerList[t];
    s && (s.stopPlayer(), delete e.playerList[t], --e.playerCount), e.logger.debug("zpc.sp.1.0 call success")
}

function reportPublishEvent(e, t, s) {
    if (e.streamEventMap[t]) {
        var r = e.streamEventMap[t];
        e.dataReport.addMsgExt(r, {
            stream: t,
            error: s
        }), e.dataReport.uploadReport(r, "WXPublishStream"), delete e.streamEventMap[t]
    }
}

function reportPlayEvent(e, t, s) {
    if (e.streamEventMap[t]) {
        var r = e.streamEventMap[t];
        e.dataReport.addMsgExt(r, {
            stream: t,
            error: s
        }), e.dataReport.uploadReport(r, "WXPlayStream"), delete e.streamEventMap[t]
    }
}

function getReconnectLimit(e) {
    return 1
}

function ListNode(e, t) {
    this._id = "number" == typeof e ? e : null, this._data = t || null, this.next = null, this.prev = null
}

function LinkedList() {
    this.start = new ListNode, this.end = new ListNode, this.start.next = this.end, this.start.prev = null, this.end.prev = this.start, this.end.next = null, this._idCounter = 0, this._numNodes = 0
}
ZegoStreamCenter.prototype.updatePlayingState = function (e, t, s) {
    void 0 != e && (updateStreamState(e, s, t, this.playingList), s ? (this.eventSeq += 1, this.streamEventMap[e] = this.eventSeq, this.dataReport.newReport(this.eventSeq), this.dataReport.eventStart(this.eventSeq, "GotPlayInfo")) : reportPlayEvent(this, e))
}, ZegoStreamCenter.prototype.updatePublishingState = function (e, t, s) {
    void 0 != e && (updateStreamState(e, s, t, this.publishingList), s ? (this.eventSeq += 1, this.streamEventMap[e] = this.eventSeq, this.dataReport.newReport(this.eventSeq), this.dataReport.eventStart(this.eventSeq, "GotPublishInfo")) : reportPublishEvent(this, e))
}, ZegoStreamCenter.prototype.isPlaying = function () {
    return 0 != this.playingList.length
}, ZegoStreamCenter.prototype.isPublishing = function () {
    return 0 != this.publishingList.length
}, ZegoStreamCenter.prototype.startPlayingStream = function (e, t, s) {
    this.logger.debug("zpc.sps.0 call");
    var r = this.streamEventMap[e];
    if (r) {
        var o = "";
        0 == s ? o = "cdn" : 1 == s && (o = "ultra_src"), this.dataReport.eventEndWithMsg(r, "GotPlayInfo", {
            type: o,
            urls: t
        })
    }
    return startPlayer(this, e, t, s, ENUM_PLAYER_TYPE.play)
}, ZegoStreamCenter.prototype.stopPlayingStream = function (e) {
    this.logger.debug("zpc.sps.1.0 call"), void 0 != e && (stopPlayer(this, e), this.updatePlayingState(e))
}, ZegoStreamCenter.prototype.startPublishingStream = function (e, t, s) {
    this.logger.debug("zpc.sps.1 call");
    var r = this.streamEventMap[e];
    if (r) {
        var o = "";
        0 == s ? o = "cdn" : 1 == s && (o = "ultra_src"), this.dataReport.eventEndWithMsg(r, "GotPublishInfo", {
            type: o,
            urls: t
        })
    }
    return startPlayer(this, e, t, s, ENUM_PLAYER_TYPE.publish)
}, ZegoStreamCenter.prototype.stopPublishingStream = function (e) {
    this.logger.debug("zpc.sps.1.1 call"), void 0 != e && (stopPlayer(this, e), this.updatePublishingState(e, !1))
}, ZegoStreamCenter.prototype.updatePlayerState = function (e, t) {
    var s = this.playerList[e];
    s && s.updateEvent(t), this.logger.debug("zpc.upe.1.0 updatePlayerEvent success")
}, ZegoStreamCenter.prototype.updatePlayerNetStatus = function (e, t) {
    var s = this.playerList[e];
    s && s.updatePlayerNetStatus(t), this.logger.debug("zpc.upns.1.0 updatePlayerNetStatus success")
}, ZegoStreamCenter.prototype.reset = function () {
    this.logger.debug("zpc.r.0 call");
    for (var e = 0; e < this.playingList.length; e++) this.stopPlayingStream(this.playingList[e]);
    for (var t = 0; t < this.publishingList.length; t++) this.stopPublishingStream(this.publishingList[t]);
    this.playerCount = 0, this.playerList = {}, this.playerWaitingList = [], this.playerStatistics = {}, this.streamEventMap = {}, this.logger.debug("zpc.r.0 call success")
}, ZegoStreamCenter.prototype.onPlayStateUpdate = function (e, t, s) {
}, ZegoStreamCenter.prototype.onPlayQualityUpdate = function (e, t) {
}, ZegoStreamCenter.prototype.onPublishStateUpdate = function (e, t, s) {
}, ZegoStreamCenter.prototype.onPublishQualityUpdate = function (e, t) {
}, ZegoStreamCenter.prototype.onPlayerStreamUrlUpdate = function (e, t, s) {
}, ZegoStreamCenter.prototype.onVideoSizeChange = function (e) {
}, ZegoStreamCenter.prototype.onPlayerStart = function (e, t) {
    this.logger.debug("ops.0 call"), t == ENUM_PLAYER_TYPE.play ? this.onPlayStateUpdate(ENUM_PLAY_STATE_UPDATE.start, e, 0) : t == ENUM_PLAYER_TYPE.publish && this.onPublishStateUpdate(ENUM_PLAY_STATE_UPDATE.start, e, 0)
}, ZegoStreamCenter.prototype.onPlayerStop = function (e, t, s) {
    this.logger.debug("ops.1 call"), t == ENUM_PLAYER_TYPE.play ? (reportPlayEvent(this, e, s), this.logger.warn("ops.1 play error"), this.onPlayStateUpdate(ENUM_PLAY_STATE_UPDATE.stop, e, s)) : t == ENUM_PLAYER_TYPE.publish && (reportPublishEvent(this, e, s), this.logger.warn("ops.1 publish error"), this.onPublishStateUpdate(ENUM_PLAY_STATE_UPDATE.stop, e, s))
}, ZegoStreamCenter.prototype.onPlayerRetry = function (e, t) {
    this.logger.debug("opr.0 call"), t == ENUM_PLAYER_TYPE.play ? this.onPlayStateUpdate(ENUM_PLAY_STATE_UPDATE.retry, e, 0) : t == ENUM_PLAYER_TYPE.publish && this.onPublishStateUpdate(ENUM_PLAY_STATE_UPDATE.retry, e, 0)
}, ZegoStreamCenter.prototype.onPlayerQuality = function (e, t, s) {
    s == ENUM_PLAYER_TYPE.play ? this.onPlayQualityUpdate(e, t) : s == ENUM_PLAYER_TYPE.play && this.onPublishQualityUpdate(e, t)
}, ZegoStreamCenter.prototype.onStreamUrlUpdate = function (e, t, s) {
    this.logger.debug("opuu.0 call"), this.onPlayerStreamUrlUpdate(e, t, s)
}, ZegoStreamCenter.prototype.onPlayerVideoSizeChanged = function (e) {
    this.onVideoSizeChange(e)
}, ListNode.prototype = {
    id: function (e) {
        if (null === e || void 0 === e) return this._id;
        if ("number" != typeof e) throw new Error("Id must be an integer.");
        this._id = e
    }, data: function (e) {
        if (null === e || void 0 === e) return this._data;
        this._data = e
    }, hasNext: function () {
        return null !== this.next && null !== this.next.id()
    }, hasPrev: function () {
        return null !== this.prev && null !== this.prev.id()
    }
}, LinkedList.prototype = {
    insertBefore: function (e, t) {
        var s = new ListNode(this._idCounter, t);
        return s.next = e, s.prev = e.prev, e.prev.next = s, e.prev = s, ++this._idCounter, ++this._numNodes, s
    }, addLast: function (e) {
        return this.insertBefore(this.end, e)
    }, add: function (e) {
        return this.addLast(e)
    }, getFirst: function () {
        return 0 === this._numNodes ? null : this.start.next
    }, getLast: function () {
        return 0 === this._numNodes ? null : this.end.prev
    }, size: function () {
        return this._numNodes
    }, getFromFirst: function (e) {
        var t = 0,
            s = this.start.next;
        if (e >= 0)
            for (; t < e && null !== s;) s = s.next, ++t;
        else s = null;
        if (null === s) throw "Index out of bounds.";
        return s
    }, get: function (e) {
        return 0 === e ? this.getFirst() : e === this._numNodes - 1 ? this.getLast() : this.getFromFirst(e)
    }, remove: function (e) {
        return e.prev.next = e.next, e.next.prev = e.prev, --this._numNodes, e
    }, removeFirst: function () {
        var e = null;
        return this._numNodes > 0 && (e = this.remove(this.start.next)), e
    }, removeLast: function () {
        var e = null;
        return this._numNodes > 0 && (e = this.remove(this.end.prev)), e
    }, removeAll: function () {
        this.start.next = this.end, this.end.prev = this.start, this._numNodes = 0, this._idCounter = 0
    }, each: function (e) {
        for (var t = this.start; t.hasNext();) e(t = t.next)
    }, find: function (e) {
        for (var t = this.start, s = !1, r = null; t.hasNext() && !s;) e(t = t.next) && (r = t, s = !0);
        return r
    }, map: function (e) {
        for (var t = this.start, s = []; t.hasNext();) e(t = t.next) && s.push(t);
        return s
    }, push: function (e) {
        return this.addLast(e)
    }, unshift: function (e) {
        this._numNodes > 0 ? this.insertBefore(this.start.next, e) : this.insertBefore(this.end, e)
    }, pop: function () {
        return this.removeLast()
    }, shift: function () {
        return this.removeFirst()
    }
};
var ENUM_LOG_LEVEL = {
        debug: 0,
        info: 1,
        warn: 2,
        error: 3,
        report: 99,
        disable: 100
    },
    ENUM_REMOTE_TYPE = {
        disable: 0,
        websocket: 1,
        https: 2
    };

function ZegoLogger() {
    this.logSeq = 0, this.logLevel = ENUM_LOG_LEVEL.disable, this.logRemoteLevel = ENUM_LOG_LEVEL.disable, this.websocket = null, this.url = "", this.appid = 0, this.sessionid = "0", this.roomid = "", this.userid = "", this.userName = "", this.logCache = [], this.logCacheSend = [], this.logCacheMax = 100, this.logType = ENUM_REMOTE_TYPE.disable, this.logUploadTimer = null, this.logUploadInterval = 1e4, this.version = ""
}
ZegoLogger.prototype.setLogLevel = function (e) {
    this.logLevel = e, (this.logLevel < ENUM_LOG_LEVEL.debug || this.logLevel > ENUM_LOG_LEVEL.report) && (this.logLevel = ENUM_LOG_LEVEL.disable)
}, ZegoLogger.prototype.setRemoteLogLevel = function (e) {
    this.logRemoteLevel = e, (this.logRemoteLevel < ENUM_LOG_LEVEL.debug || this.logRemoteLevel > ENUM_LOG_LEVEL.report) && (this.logRemoteLevel = ENUM_LOG_LEVEL.disable)
}, ZegoLogger.prototype.setSessionInfo = function (e, t, s, r, o, i) {
    this.appid = e, this.roomid = t, this.sessionid = s, this.userid = r, this.userName = o, this.version = i
}, ZegoLogger.prototype.openLogServer = function (e) {
    0 == e.indexOf("wss:") ? (this.logType = ENUM_REMOTE_TYPE.websocket, openWebSocketLogServer(this, e)) : 0 == e.indexOf("https:") ? (this.logType = ENUM_REMOTE_TYPE.https, openHttpsLogServer(this, e)) : this.logType = ENUM_REMOTE_TYPE.disable
}, ZegoLogger.prototype.stopLogServer = function () {
    this.logType == ENUM_REMOTE_TYPE.websocket ? stopWebSocketServer(this) : this.logType == ENUM_LOG_LEVEL.https && (SendHttpsLog(this), stopHttpsServer(this)), this.logType = ENUM_REMOTE_TYPE.disable
}, ZegoLogger.prototype.RemoteLog = function (e, t, s) {
    "" != this.url && (this.logType == ENUM_REMOTE_TYPE.websocket ? RemoteWebSocketLog(this, e, t) : this.logType == ENUM_REMOTE_TYPE.https && RemoteHttpsLog(this, e, t, s))
}, ZegoLogger.prototype.log = function (e, t) {
    if (this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= e)
        for (this.logCache.push(t); this.logCache.length > this.logCacheMax;) this.logCache.shift();
    this.logRemoteLevel !== ENUM_LOG_LEVEL.disable && this.logRemoteLevel <= e && this.RemoteLog(e, t)
}, ZegoLogger.prototype.debug = function () {
    var e = logParamList(this, "debug", "".concat([].slice.call(arguments)));
    this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= ENUM_LOG_LEVEL.debug && console.debug.apply(console, e), this.log(ENUM_LOG_LEVEL.debug, e)
}, ZegoLogger.prototype.info = function () {
    var e = logParamList(this, "info", "".concat([].slice.call(arguments)));
    this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= ENUM_LOG_LEVEL.info && console.info.apply(console, e), this.log(ENUM_LOG_LEVEL.info, e)
}, ZegoLogger.prototype.warn = function () {
    var e = logParamList(this, "warn", "".concat([].slice.call(arguments)));
    this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= ENUM_LOG_LEVEL.warn && console.warn.apply(console, e), this.log(ENUM_LOG_LEVEL.warn, e)
}, ZegoLogger.prototype.error = function () {
    var e = logParamList(this, "error", "".concat([].slice.call(arguments)));
    this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= ENUM_LOG_LEVEL.error && console.error.apply(console, e), this.log(ENUM_LOG_LEVEL.error, e)
}, ZegoLogger.prototype.report = function (e) {
    var t = logReportParamList(this, "report", e);
    this.logLevel !== ENUM_LOG_LEVEL.disable && this.logLevel <= ENUM_LOG_LEVEL.report && console.debug.apply(console, t), this.RemoteLog(ENUM_LOG_LEVEL.report, t, !0)
};
var D = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"];

function logReportParamList(e, t, s) {
    var r = new Date,
        o = 1900 + r.getYear() + "/";
    return o += (D[r.getMonth() + 1] || r.getMonth() + 1) + "/", o += (D[r.getDate()] || r.getDate()) + " ", o += (D[r.getHours()] || r.getHours()) + ":", o += (D[r.getMinutes()] || r.getMinutes()) + ":", o += D[r.getSeconds()] || r.getSeconds(), o += "." + r.getTime() % 1e3, s.time = o, s.level = t, s.console = "xcx", s.appid = e.appid, s.roomid = e.roomid, s.userid = e.userid, s.id_name = e.userid, s.userName = e.userName, s.sessionid = e.sessionid, s.version = e.version, [JSON.stringify(s)]
}

function logParamList(e, t, s) {
    var r = new Date,
        o = 1900 + r.getYear() + "/";
    o += (D[r.getMonth() + 1] || r.getMonth() + 1) + "/", o += (D[r.getDate()] || r.getDate()) + " ", o += (D[r.getHours()] || r.getHours()) + ":", o += (D[r.getMinutes()] || r.getMinutes()) + ":", o += D[r.getSeconds()] || r.getSeconds(), o += "." + r.getTime() % 1e3;
    var i = s.substr(0, s.indexOf(" "));
    0 == i.length && (i = s);
    var a = s.substr(s.indexOf(" ") + 1);
    0 == a.length && (a = "");
    var n = {
        time: o,
        level: t,
        action: i,
        content: a,
        appid: e.appid,
        roomid: e.roomid,
        userid: e.userid,
        userName: e.userName,
        sessionid: e.sessionid
    };
    return [JSON.stringify(n)]
}

function openWebSocketLogServer(e, t) {
    if (e.url != t) {
        if (e.url = t, stopWebSocketServer(e), !t) return;
        e.websocket = new ZegoWebSocket(t), e.websocket.onopen = function (e) {
        }, e.websocket.onclose = function (e) {
        }, e.websocket.onmessage = function (e) {
        }, e.websocket.onerror = function (e) {
            console.log("ws发生错误！")
        }
    }
}

function openHttpsLogServer(e, t) {
    e.url = t, t && (stopHttpsServer(e), e.logUploadTimer || (e.logUploadTimer = setInterval(function () {
        SendHttpsLog(e)
    }, e.logUploadInterval)))
}

function stopWebSocketServer(e) {
    e.websocket && (e.websocket.onclose = null, e.websocket.onerror = null, e.websocket.close(), e.websocket = null)
}

function stopHttpsServer(e) {
    e.logUploadTimer && (clearInterval(e.logUploadTimer), e.logUploadTimer = null)
}

function RemoteWebSocketLog(e, t, s) {
    if (null == e.websocket || 2 == e.websocket.readyState || 3 == e.websocket.readyState) {
        var r = e.url;
        e.url = "", e.openLogServer(r), e.logCacheSend.length < e.logCacheMax && e.logCacheSend.push(s)
    } else if (0 == e.websocket.readyState) e.logCacheSend.length < e.logCacheMax && e.logCacheSend.push(s);
    else if (1 == e.websocket.readyState) {
        if (e.logCacheSend > 0) {
            for (var o = "", i = 0; i < e.logCacheSend.length; i++) o = o + e.logCacheSend[i] + "\n";
            s = o + s, e.logCacheSend = []
        }
        e.websocket.send(s)
    } else e.logCacheSend.length < e.logCacheMax && e.logCacheSend.push(s)
}

function RemoteHttpsLog(e, t, s, r) {
    e.logCacheSend.push(s), (e.logCacheSend.length >= e.logCacheMax || !0 === r) && SendHttpsLog(e)
}

function SendHttpsLog(e) {
    if (0 != e.logCacheSend.length) {
        for (var t = "", s = 0; s < e.logCacheSend.length; s++) t = t + e.logCacheSend[s] + "\n";
        wx.request({
            url: e.url,
            data: t,
            method: "POST",
            success: function (t) {
                if (0 != t.data.length) {
                    var s = t.data.interval;
                    "number" == typeof s && e.logUploadInterval !== s && (e.timeInterval = s, openHttpsLogServer(e, e.url))
                }
            }, fail: function (e) {
                console.log("send failed " + e.statusCode)
            }
        }), e.logCacheSend = []
    }
}
var ENUM_PLAY_SOURCE_TYPE = {
        auto: 0,
        ultra: 1
    },
    ENUM_DISPATCH_TYPE = {
        cdn: 0,
        ultra: 1
    },
    ENUM_RUN_STATE = {
        logout: 0,
        trylogin: 1,
        login: 2
    },
    ENUM_PUBLISH_STREAM_STATE = {
        waiting_url: 1,
        tryPublish: 2,
        update_info: 3,
        publishing: 4,
        stop: 5
    },
    ENUM_STREAM_SUB_CMD = {
        liveNone: 0,
        liveBegin: 2001,
        liveEnd: 2002,
        liveUpdate: 2003
    },
    ENUM_STREAM_UPDATE_TYPE = {
        added: 0,
        deleted: 1
    },
    ENUM_STREAM_UPDATE_CMD = {
        added: 12001,
        deleted: 12002,
        updated: 12003
    },
    MAX_TRY_LOGIN_COUNT = 5,
    TRY_LOGIN_INTERVAL = [2e3, 2e3, 3e3, 3e3, 4e3],
    MAX_TRY_HEARTBEAT_COUNT = 3,
    MINIUM_HEARTBEAT_INTERVAL = 3e3,
    PROTO_VERSION = "1.0.3",
    ENUM_SIGNAL_SUB_CMD = {
        none: 0,
        joinLiveRequest: 1001,
        joinLiveResult: 1002,
        joinLiveInvite: 1003,
        joinLiveStop: 1004
    },
    ENUM_PUSH_SIGNAL_SUB_CMD = {
        none: 0,
        pushJoinLiveRequest: 11001,
        pushJoinLiveResult: 11002,
        pushJoinLiveInvite: 11003,
        pushJoinLiveStop: 11004
    };

function ZegoClient() {
    this.appid = 0, this.server = "", this.idName = "", this.nickName = "", this.configOK = !1, this.logger = new ZegoLogger, this.userStateUpdate = !1, this.userSeq = 0, this.userQuerying = !1, this.userTempList = [], this.roomCreateFlag = 1, this.roomid = "", this.token = "", this.role = 0, this.callbackList = {}, this.runState = ENUM_RUN_STATE.logout, this.lastRunState = ENUM_RUN_STATE.logout, this.userid = "", this.sessionid = "", this.cmdSeq = 0, this.websocket = null, this.globalHeader = null, this.tryLoginCount = 0, this.tryLoginTimer = null, this.tryHeartbeatCount = 0, this.tryHeartbeatTimer = null, this.heartbeatInterval = 3e4, this.ultraPlaySourceType = "rtmp_v2", this.streamList = [], this.streamQuerying = !1, this.preferPlaySourceType = ENUM_PLAY_SOURCE_TYPE.auto, this.preferPublishSourceType = ENUM_DISPATCH_TYPE.ultra, this.currentPlaySourceType = ENUM_DISPATCH_TYPE.cdn, this.streamCenter = new ZegoStreamCenter(this.logger), this.streamCenter.onPlayStateUpdate = this.onPlayStateUpdateHandle.bind(this), this.streamCenter.onPlayQualityUpdate = this.onPlayQualityUpdateHandle.bind(this), this.streamCenter.onPublishStateUpdate = this.onPublishStateUpdateHandle.bind(this), this.streamCenter.onPublishQualityUpdate = this.onPublishQualityUpdateHandle.bind(this), this.streamCenter.onPlayerStreamUrlUpdate && (this.streamCenter.onPlayerStreamUrlUpdate = this.onStreamUrlUpdateHandle.bind(this)), this.streamCenter.onVideoSizeChanged && (this.streamCenter.onVideoSizeChanged = this.onVideoSizeChangedHandle.bind(this)), this.sendDataMap = {}, this.sendDataList = new LinkedList, this.sendDataCheckTimer = null, this.sendDataCheckInterval = 2e3, this.sendDataTimeout = 5e3, this.sendDataDropTimeout = 1e4, this.sendDataCheckOnceCount = 100, this.sendRoomMsgTime = 0, this.SendRoomMsgInterval = 500, this.joinLiveCallbackMap = {}, this.joinLiveRequestMap = {}, this.publishStreamList = {}, this.sendCommandMap = {}, this.sendCommandList = new LinkedList, this.streamUrlMap = {}, this.serverTimeOffset = 0, this.bigimTimeWindow = 0, this.datiTimeWindow = 0, this.transSeqMap = {}, this.bigImLastTimeIndex = 0, this.bigImMessageList = [], this.bigImTimer = null, this.bigImCallbackMap = {}, this.realyMessageList = [], this.relayTimer = null, this.cmdCallback = {}
}

function startPlayingStreamFromCDN(e, t) {
    e.logger.debug("zc.p.spsfc.0 call");
    for (var s = null, r = 0; r < e.streamList.length; r++)
        if (e.streamList[r].stream_id === t) {
            s = e.streamList[r].url_rtmp || [];
            break
        }
    return !s || s.length <= 0 ? (e.logger.error("zc.p.spsfc.0 cannot find stream url"), !1) : (e.currentPlaySourceType = ENUM_DISPATCH_TYPE.cdn, e.logger.debug("zc.p.spsfc.0 play stream"), doPlayStream(e, t, [s]))
}

function startPlayingStreamFromBGP(e, t) {
    return e.currentPlaySourceType = ENUM_DISPATCH_TYPE.ultra, e.logger.info("zc.p.sps.0 fetch stream url"), fetchPlayStreamUrl(e, t), !0
}

function fetchPublishStreamUrl(e, t) {
    if (e.logger.debug("fpsu.0 call"), e.runState === ENUM_RUN_STATE.login) {
        e.logger.info("fpsu.0 send fetch publish request");
        var s = "";
        e.preferPublishSourceType == ENUM_DISPATCH_TYPE.cdn ? s = "cdn" : e.preferPublishSourceType == ENUM_DISPATCH_TYPE.ultra && (s = "bgp");
        var r = sendMessage(e, "stream_publish", {
            stream_id: t,
            url_type: e.ultraPlaySourceType,
            publish_type: s
        });
        -1 == r ? (e.onPublishStateUpdate(1, t, -1), e.streamCenter.stopPublishingStream(t)) : e.streamUrlMap[r] = t, e.logger.debug("fpsu.0 call success")
    } else e.logger.info("fpsu.0 state error")
}

function fetchPlayStreamUrl(e, t) {
    if (e.logger.debug("fsu.0 call"), e.runState === ENUM_RUN_STATE.login) {
        e.logger.info("fsu.0 send fetch request");
        var s = sendMessage(e, "stream_url", {
            stream_ids: [t],
            url_type: e.ultraPlaySourceType
        });
        -1 == s ? e.onPlayStateUpdate(1, t, -1) : e.streamUrlMap[s] = t, e.logger.debug("fsu.0 call success")
    } else e.logger.info("fsu.0 state error")
}

function doPlayStream(e, t, s) {
    return e.logger.debug("zc.p.dps.0 call"), !(!s || s.length <= 0) && (e.streamCenter.startPlayingStream(t, s, e.currentPlaySourceType), !0)
}

function doPublishStream(e, t, s) {
    return e.logger.debug("zc.p.dps.1 call"), !(!s || s.length <= 0) && (e.logger.info("zc.p.dps.1 streamid: " + t + "streamUrl: " + s), e.streamCenter.startPublishingStream(t, s, e.preferPublishSourceType), e.logger.debug("zc.p.dps.1 call success"), !0)
}

function handleFetchStreamPublishUrlRsp(e, t) {
    e.logger.debug("hfspur.0 call");
    var s = e.streamUrlMap[t.header.seq];
    if (s && delete e.streamUrlMap[t.header.seq], 0 !== t.body.err_code) return e.logger.info("hfspur.0 server error=", t.body.err_code), void(e.publishStreamList[s] && (e.onPublishStateUpdate(1, s, t.body.err_code), e.streamCenter.stopPublishingStream(s)));
    if (t.body.stream_url_info) {
        var r = t.body.stream_url_info.stream_id,
            o = t.body.stream_url_info.urls_ws;
        if (!e.publishStreamList[r]) return void e.logger.info("hfspur.0 cannot find stream");
        e.publishStreamList[r].url_rtmp = o, e.publishStreamList[r].state = ENUM_PUBLISH_STREAM_STATE.tryPublish, doPublishStream(e, r, o)
    }
}

function handleFetchStreamUrlRsp(e, t) {
    e.logger.debug("hfsur.0 call");
    var s = e.streamUrlMap[t.header.seq];
    if (s && delete e.streamUrlMap[t.header.seq], 0 !== t.body.err_code) return e.logger.debug("hfsur.0 server error=", t.body.err_code), void e.onPlayStateUpdate(1, s, t.body.err_code);
    if (t.body.stream_url_infos && t.body.stream_url_infos.length > 0) {
        for (var r = t.body.stream_url_infos[0].stream_id, o = t.body.stream_url_infos[0].urls_ws, i = !1, a = 0; a < e.streamList.length; a++)
            if (e.streamList[a].stream_id == r) {
                e.streamList[a].urltra_url_rtmp = o, i = !0;
                break
            }
        i || e.streamList.push({
            stream_id: r,
            urltra_url_rtmp: o
        }), doPlayStream(e, r, o)
    }
    e.logger.debug("hfsur.0 call success")
}

function getHeader(e, t) {
    return e.globalHeader = {
        Protocol: "req",
        cmd: t,
        appid: e.appid,
        seq: ++e.cmdSeq,
        user_id: e.userid,
        session_id: e.sessionid,
        room_id: e.roomid
    }, e.globalHeader
}

function sendMessage(e, t, s, r, o) {
    if (e.logger.debug("sm.0 call " + t), !e.websocket || 1 !== e.websocket.readyState) return e.logger.info("sm.0 error"), -1;
    var i = getHeader(e, t),
        a = {
            header: i,
            body: s
        },
        n = JSON.stringify(a);
    if (void 0 == r && (r = null), void 0 == o && (o = null), null != r || null != o) {
        var l = {
                data: a,
                seq: i.seq,
                deleted: !1,
                time: Date.parse(new Date),
                success: r,
                error: o
            },
            g = e.sendCommandList.push(l);
        e.sendCommandMap[l.seq] = g
    }
    return e.websocket.send(n), e.logger.debug("sm.0 success"), i.seq
}

function sendCustomMessage(e, t, s, r, o) {
    if (e.logger.debug("scm.0 call"), !e.websocket || 1 !== e.websocket.readyState) return e.logger.info("scm.0 error"), !1;
    var i = getHeader(e, t),
        a = {
            header: i,
            body: s
        },
        n = JSON.stringify(a);
    void 0 == r && (r = null), void 0 == o && (o = null);
    var l = {
            data: a,
            seq: i.seq,
            deleted: !1,
            time: Date.parse(new Date),
            success: r,
            error: o
        },
        g = e.sendDataList.push(l);
    return e.sendDataMap[l.seq] = g, e.websocket.send(n), e.logger.debug("scm.0 success seq: ", i.seq), !0
}

function checkConfigParam(e) {
    return !0
}

function checkLoginParam(e) {
    return !0
}

function checkCustomCommandParam(e) {
    return !0
}

function registerCallback(e, t, s) {
    var r = function () {
        },
        o = function () {
        };
    s.success && "function" == typeof s.success && (r = s.success), s.error && "function" == typeof s.error && (o = s.error), e.callbackList[t + "SuccessCallback"] = r, e.callbackList[t + "ErrorCallback"] = o
}

function actionSuccessCallback(e, t) {
    return e.callbackList[t + "SuccessCallback"]
}

function actionErrorCallback(e, t) {
    return e.callbackList[t + "ErrorCallback"]
}

function getServerError(e) {
    var t = {
        1: "parse json error.",
        1001: "login is processing.",
        1002: "liveroom request error.",
        1003: "zpush connect fail.",
        1004: "zpush handshake fail.",
        1005: "zpush login fail.",
        1006: "user login state is wrong.",
        1007: "got no zpush addr",
        1008: "token error",
        1009: "dispatch error",
        1000000000: "liveroom cmd error, result="
    };
    if (0 === e) return {
        code: "ZegoClient.Success",
        msg: "success"
    };
    var s = {
        code: "ZegoClient.Error.Server"
    };
    return s.msg = e > 1e9 ? t[1e9] + e : void 0 != t[e] ? t[e] : "unknown error code:" + e, s
}
ZegoClient.prototype.onPlayStateUpdateHandle = function (e, t, s) {
    1 == e && this.stopPlayingStream(t), this.onPlayStateUpdate(e, t, s)
}, ZegoClient.prototype.onPlayQualityUpdateHandle = function (e, t) {
    this.onPlayQualityUpdate(e, t)
}, ZegoClient.prototype.onPublishStateUpdateHandle = function (e, t, s) {
    if (0 == e) {
        if (this.publishStreamList[t] && this.publishStreamList[t].state == ENUM_PUBLISH_STREAM_STATE.tryPublish) {
            this.publishStreamList[t].state = ENUM_PUBLISH_STREAM_STATE.update_info;
            var r = this;
            updateStreamInfo(this, t, ENUM_STREAM_SUB_CMD.liveBegin, this.publishStreamList[t].extra_info, function (e) {
                r.publishStreamList[t] && r.publishStreamList[t].state == ENUM_PUBLISH_STREAM_STATE.update_info && (r.publishStreamList[t].state = ENUM_PUBLISH_STREAM_STATE.stop, r.onPublishStateUpdate(1, t, e), r.streamCenter.stopPlayingStream(t))
            })
        }
    } else 1 == e && this.stopPublishingStream(t), this.onPublishStateUpdate(e, t, s)
}, ZegoClient.prototype.onPublishQualityUpdateHandle = function (e, t) {
    this.onPublishQualityUpdate(e, t)
}, ZegoClient.prototype.onVideoSizeChangedHandle = function (e, t, s) {
    this.onVideoSizeChanged(e, t, s)
}, ZegoClient.prototype.onStreamUrlUpdateHandle = function (e, t, s) {
    this.onStreamUrlUpdate(e, t, s)
}, ZegoClient.prototype.setPreferPlaySourceType = function (e) {
    return this.logger.debug("zc.p.sppst.0 call"), "number" != typeof e || e !== ENUM_PLAY_SOURCE_TYPE.auto && e !== ENUM_PLAY_SOURCE_TYPE.ultra ? (this.logger.info("zc.p.sppst.0 param error"), !1) : (this.preferPlaySourceType = e, this.logger.debug("zc.p.sppst.0 call success"), !0)
}, ZegoClient.prototype.setPreferPublishSourceType = function (e) {
    return this.logger.debug("zc.p.sppst.1 call"), "number" != typeof e || e !== ENUM_DISPATCH_TYPE.cdn && e !== ENUM_DISPATCH_TYPE.ultra ? (this.logger.info("zc.p.sppst.1 param error"), !1) : (this.preferPublishSourceType = e, this.logger.debug("zc.p.sppst.1 call success"), !0)
}, ZegoClient.prototype.startPlayingStream = function (e, t) {
    return this.logger.debug("zc.p.sps.0 call"), e && "" !== e ? this.runState != ENUM_RUN_STATE.login ? (this.logger.info("zc.p.sps.0 not login"), !1) : (this.streamCenter.updatePlayingState(e, t, !0), this.streamCenter.isPublishing() ? this.preferPublishSourceType == ENUM_DISPATCH_TYPE.cdn ? startPlayingStreamFromCDN(this, e) : startPlayingStreamFromBGP(this, e) : this.preferPlaySourceType == ENUM_PLAY_SOURCE_TYPE.ultra ? startPlayingStreamFromBGP(this, e) : startPlayingStreamFromCDN(this, e)) : (this.logger.info("zc.p.sps.0 param error"), !1)
}, ZegoClient.prototype.stopPlayingStream = function (e) {
    return this.logger.debug("zc.p.sps.1.0 call"), e && "" !== e ? (this.streamCenter.stopPlayingStream(e), this.streamUrlMap[e] && delete this.streamUrlMap[e], this.logger.debug("zc.p.sps.1.0 call success"), !0) : (this.logger.info("zc.p.sps.1.0 param error"), !1)
}, ZegoClient.prototype.startPublishingStream = function (e, t, s) {
    if (this.logger.debug("zc.p.sps.1 call"), !e || "" === e) return this.logger.info("zc.p.sps.1 param error"), !1;
    if (this.runState != ENUM_RUN_STATE.login) return this.logger.info("zc.p.sps.1 not login"), !1;
    if (this.publishStreamList[e] = {
            state: ENUM_PUBLISH_STREAM_STATE.waiting_url,
            extra_info: s
        }, this.logger.info("zc.p.sps.0 fetch stream url"), this.streamCenter.updatePublishingState(e, t, !0), fetchPublishStreamUrl(this, e), this.streamCenter.isPlaying() && this.preferPublishSourceType == ENUM_PLAY_SOURCE_TYPE.ultra && this.currentPlaySourceType == ENUM_DISPATCH_TYPE.cdn)
        for (var r = 0; r < this.streamCenter.playingList.length; r++) {
            var o = this.streamCenter.playingList[r].streamid,
                i = this.streamCenter.playingList[r].params;
            this.stopPlayingStream(o), this.streamCenter.updatePlayingState(o, i, !0), startPlayingStreamFromBGP(this, o)
        }
    return !0
}, ZegoClient.prototype.stopPublishingStream = function (e) {
    return this.logger.debug("zc.p.sps.1.1 call"), e && "" !== e ? (this.streamCenter.stopPublishingStream(e), this.publishStreamList[e] && (this.publishStreamList[e].state >= ENUM_PUBLISH_STREAM_STATE.update_info && updateStreamInfo(this, e, ENUM_STREAM_SUB_CMD.liveEnd), delete this.publishStreamList[e]), this.streamUrlMap[e] && delete this.streamUrlMap[e], this.logger.debug("zc.p.sps.1.1 call success"), !0) : (this.logger.info("zc.p.sps.1.1 param error"), !1)
}, ZegoClient.prototype.updatePlayerState = function (e, t) {
    this.logger.debug("zc.p.upe.0 call"), this.streamCenter.updatePlayerState(e, t)
}, ZegoClient.prototype.updatePlayerNetStatus = function (e, t) {
    this.logger.debug("zc.p.upns.0 call"), this.streamCenter.updatePlayerNetStatus(e, t)
}, ZegoClient.prototype.config = function (e) {
    return this.logger.debug("zc.p.c.0 call"), checkConfigParam(e) ? (this.appid = e.appid, this.server = e.server, this.idName = e.idName, this.nickName = e.nickName, this.logger.setLogLevel(e.logLevel), !1 === e.audienceCreateRoom && (this.roomCreateFlag = 0), void 0 != e.remoteLogLevel ? this.logger.setRemoteLogLevel(e.remoteLogLevel) : this.logger.setRemoteLogLevel(0), this.logger.setSessionInfo(e.appid, "", "", e.idName, "", PROTO_VERSION), void 0 != e.logUrl && 0 != e.logUrl.length && this.logger.openLogServer(e.logUrl), this.configOK = !0, this.logger.debug("zc.p.c.0 call success"), !0) : (this.logger.info("zc.p.c.0 fail"), !1)
}, ZegoClient.prototype.login = function (e, t, s, r, o) {
    return this.logger.setSessionInfo(this.appid, e, "", this.idName, "", PROTO_VERSION), this.logger.info("zc.p.l.0 call:", e, s), this.configOK && checkLoginParam({
        roomid: e,
        token: s
    }) ? (this.runState !== ENUM_RUN_STATE.logout && (this.logger.debug("zc.p.l.0 reset"), setRunState(this, ENUM_RUN_STATE.logout), resetRoom(this)), this.logger.debug("zc.p.l.0 begin"), setRunState(this, ENUM_RUN_STATE.trylogin), this.roomid = e, this.token = s, this.role = t, registerCallback(this, "login", {
        success: r,
        error: o
    }), resetTryLogin(this), tryLogin(this), this.logger.info("zc.p.l.0 call success"), !0) : (this.logger.info("zc.p.l.0 param error"), !1)
}, ZegoClient.prototype.logout = function () {
    return this.logger.debug("zc.p.l.1.0 call"), this.runState === ENUM_RUN_STATE.logout ? (this.logger.info("zc.p.l.1.0 at logout"), !1) : (setRunState(this, ENUM_RUN_STATE.logout), resetRoom(this), this.logger.debug("zc.p.l.1.0 call success"), !0)
}, ZegoClient.prototype.setUserStateUpdate = function (e) {
    return this.logger.debug("zc.p.eusu.0 call"), "boolean" != typeof e ? (this.logger.info("zp.p.eusu.0 param error"), !1) : (this.userStateUpdate = e, this.logger.debug("zc.p.eusu.0 call success " + e), !0)
}, ZegoClient.prototype.sendCustomCommand = function (e, t, s, r) {
    if (this.logger.debug("zc.p.scc.0 call"), this.runState !== ENUM_RUN_STATE.login) return this.logger.info("zc.p.scc.0 state error"), !1;
    if (!(e && e instanceof Array && 0 != e.length)) return this.logger.info("zc.p.scc.0 dstMembers error"), !1;
    var o = {
        dest_id_name: e,
        custom_msg: t
    };
    return checkCustomCommandParam(o) ? (sendCustomMessage(this, "custommsg", o, s, r), this.logger.debug("zc.p.scc.0 call success"), !0) : (this.logger.info("zc.p.scc.0 param error"), !1)
}, ZegoClient.prototype.sendRoomMsg = function (e, t, s, r, o) {
    if (this.logger.debug("srm.0 call"), this.runState === ENUM_RUN_STATE.login) {
        var i = Date.parse(new Date);
        if (this.sendRoomMsgTime > 0 && this.sendRoomMsgTime + this.SendRoomMsgInterval > i) return this.logger.info("srm.0 freq error"), void(o && o(sdkErrorList.FREQ_LIMITED, 0, e, t, s));
        this.sendRoomMsgTime = i, this.logger.debug("srm.0 send fetch request"), sendCustomMessage(this, "im_chat", {
            msg_category: e,
            msg_type: t,
            msg_content: s
        }, r, o), this.logger.debug("srm.0 call success")
    } else this.logger.info("srm.0 state error")
}, ZegoClient.prototype.updateStreamExtraInfo = function (e, t) {
    return this.logger.debug("zc.p.usei.0 call"), e && "" !== e ? "string" == typeof t && (this.publishStreamList[e] && (this.publishStreamList[e].extra_info = t, this.publishStreamList[e].state >= ENUM_PUBLISH_STREAM_STATE.update_info && updateStreamInfo(this, e, ENUM_STREAM_SUB_CMD.liveUpdate, t)), !0) : (this.logger.info("zc.p.usei.0 param error"), !1)
}, ZegoClient.prototype.release = function () {
    this.logger.debug("zc.p.r.0 call"), setRunState(this, ENUM_RUN_STATE.logout), resetRoom(this), this.logger.stopLogServer(), this.logger.debug("zc.p.r.0 call success")
}, ZegoClient.prototype.requestJoinLive = function (e, t, s, r) {
    this.logger.debug("zc.p.rjl.0 call");
    var o = getRequestId(this),
        i = getSignalCmdContent(this, o, e);
    return void 0 != r && (this.joinLiveCallbackMap[o] = r, sendSignalCmd(this, ENUM_SIGNAL_SUB_CMD.joinLiveRequest, i, e, t, s), !0)
}, ZegoClient.prototype.inviteJoinLive = function (e, t, s, r) {
    this.logger.debug("zc.p.ijl.0 call");
    var o = getRequestId(this),
        i = getSignalCmdContent(this, o, e);
    return void 0 != r && (this.joinLiveCallbackMap[o] = r, sendSignalCmd(this, ENUM_SIGNAL_SUB_CMD.joinLiveInvite, i, e, t, s), !0)
}, ZegoClient.prototype.respondJoinLive = function (e, t, s, r) {
    this.logger.debug("zc.p.rjl.1 call");
    var o = this.joinLiveRequestMap[e];
    if (!o) return this.logger.info("zc.p.rjl.1 no dest id name"), !1;
    var i = 0;
    !0 === t && (i = 1);
    var a = getSignalCmdContent(this, e, o, i);
    return sendSignalCmd(this, ENUM_SIGNAL_SUB_CMD.joinLiveResult, a, o, s, r), delete this.joinLiveRequestMap[e], !0
}, ZegoClient.prototype.endJoinLive = function (e, t, s) {
    this.logger.debug("zc.p.sjl.0 call");
    var r = getSignalCmdContent(this, getRequestId(this), e);
    return sendSignalCmd(this, ENUM_SIGNAL_SUB_CMD.joinLiveStop, r, e, t, s), !0
}, ZegoClient.prototype.sendReliableMessage = function (e, t, s, r) {
    this.logger.debug("zc.p.srm.0 call"), this.transSeqMap[e] && delete this.transSeqMap[e], this.transSeqMap[e] = {
        seq: 0
    }, sendMessage(this, "trans", {
        trans_type: e,
        trans_data: t
    }, s, r)
}, ZegoClient.prototype.sendRelayMessage = function (e, t, s, r) {
    this.logger.debug("zc.p.srm.1 call");
    var o = this.datiTimeWindow,
        i = this.serverTimeOffset;
    o > 0 ? (this.realyMessageList.push({
        type: e,
        data: t,
        success: s,
        error: r
    }), 1 == this.realyMessageList.length && setRelayTimer(this, i, o)) : sendRelayMessageInternal(this, e, t, s, r)
}, ZegoClient.prototype.sendBigRoomMessage = function (e, t, s, r, o) {
    this.logger.debug("zc.p.sbim.1 call");
    var i = this.bigimTimeWindow,
        a = this.serverTimeOffset,
        n = (new Date).getTime() + a,
        l = ++this.cmdSeq;
    if (l = l.toString(), void 0 == r && (r = null), void 0 == o && (o = null), this.bigImCallbackMap[l] = {
            success: r,
            error: o
        }, 0 == i) {
        var g = {
            msg_category: t,
            msg_type: e,
            msg_content: s,
            bigmsg_client_id: l
        };
        this.logger.debug("zc.p.sbim.1 no time window"), sendBigRoomMessageInternal(this, [g], handleBigImMsgRsp, o)
    } else {
        var d = Math.floor(n / i);
        if (this.logger.debug("currentIndex " + d + " lastTimeIndex " + this.bigImLastTimeIndex), this.bigImLastTimeIndex < d && 0 == this.bigImMessageList.length) this.bigImLastTimeIndex = d, sendBigRoomMessageInternal(this, [{
            msg_category: t,
            msg_type: e,
            msg_content: s,
            bigmsg_client_id: l
        }], handleBigImMsgRsp, o);
        else this.bigImMessageList.push({
            msg_category: t,
            msg_type: e,
            msg_content: s,
            bigmsg_client_id: l
        }), 1 == this.bigImMessageList.length && setBigImTimer(this, a, window)
    }
};
var sdkErrorList = {
    SUCCESS: {
        code: "ZegoClient.Success",
        msg: "success."
    },
    PARAM: {
        code: "ZegoClient.Error.Param",
        msg: "input error."
    },
    HEARTBEAT_TIMEOUT: {
        code: "ZegoClient.Error.Timeout",
        msg: "heartbeat timeout."
    },
    LOGIN_TIMEOUT: {
        code: "ZegoClient.Error.Timeout",
        msg: "login timeout."
    },
    SEND_MSG_TIMEOUT: {
        code: "ZegoClient.Error.Timeout",
        msg: "send customsg timeout."
    },
    RESET_QUEUE: {
        code: "ZegoClient.Error.Timeout",
        msg: "msg waiting ack is clear when reset."
    },
    LOGIN_DISCONNECT: {
        code: "ZegoClient.Error.Network",
        msg: "network is broken and login fail."
    },
    KICK_OUT: {
        code: "ZegoClient.Error.Kickout",
        msg: "kickout reason="
    },
    UNKNOWN: {
        code: "ZegoClient.Error.Unknown",
        msg: "unknown error."
    },
    FREQ_LIMITED: {
        code: "ZegoClient.Error.requencyLimited",
        msg: "Frequency Limited."
    }
};

function setRunState(e, t) {
    e.logger.debug("srs.0 old=" + e.runState + ", new=" + t), e.lastRunState = e.runState, e.runState = t
}

function checkMessageListTimeout(e, t, s) {
    for (var r = t.getFirst(), o = Date.parse(new Date), i = 0, a = 0, n = 0; !(null == r || r._data.time + e.sendDataTimeout > o || (delete s[r._data.data.header.seq], t.remove(r), ++a, null == r._data.error || e.sendDataDropTimeout > 0 && r._data.time + e.sendDataDropTimeout < o ? ++n : void 0 != r._data.data.body.custom_msg ? r._data.error(sdkErrorList.SEND_MSG_TIMEOUT, r._data.data.header.seq, r._data.data.body.custom_msg) : r._data.error(sdkErrorList.SEND_MSG_TIMEOUT, r._data.data.header.seq), ++i >= e.sendDataCheckOnceCount));) r = t.getFirst();
    0 == a && 0 == n || e.logger.debug("scmt.0 call success, stat: timeout=", a, "drop=", n)
}

function startCheckMessageTimeout(e) {
    e.runState === ENUM_RUN_STATE.login ? (checkMessageListTimeout(e, e.sendDataList, e.sendDataMap), checkMessageListTimeout(e, e.sendCommandList, e.sendCommandMap), e.sendDataCheckTimer = setTimeout(function () {
        startCheckMessageTimeout(e)
    }, e.sendDataCheckInterval)) : e.logger.info("scmt.0 state error")
}

function checkSendMessageList(e) {
    for (var t = e.getFirst(); null != t;) e.remove(t), null != t._data.error && (void 0 != t._data.data.body.custom_msg ? t._data.error(sdkErrorList.SEND_MSG_TIMEOUT, t._data.data.header.seq, t._data.data.body.custom_msg) : t._data.error(sdkErrorList.SEND_MSG_TIMEOUT, t._data.data.header.seq)), t = e.getFirst()
}

function resetCheckMessage(e) {
    e.logger.debug("rcm.0 call"), clearTimeout(e.sendDataCheckTimer), e.sendDataCheckTimer = null, checkSendMessageList(e.sendDataList), checkSendMessageList(e.sendCommandList), e.sendDataMap = {}, e.sendCommandMap = {}, e.logger.debug("rcm.0 call success")
}

function resetBigRoomInfo(e) {
    e.transSeqMap = {}, e.realyMessageList = [], e.relayTimer && (clearTimeout(e.relayTimer), e.relayTimer = null), e.bigImLastTimeIndex = 0, e.bigIMmessageList = [], e.bigImCallbackMap = {}, e.bigImTimer && (clearTimeout(e.bigImTimer), e.bigImTimer = null), e.serverTimeOffset = 0, e.datiTimeWindow = 0, e.bigimTimeWindow = 0
}

function resetStreamCenter(e) {
    if (e.customUrl = null, e.streamCenter.reset(), e.websocket && 1 === e.websocket.readyState)
        for (var t in e.publishStreamList) e.publishStreamList[t].state == ENUM_PUBLISH_STREAM_STATE.publishing && updateStreamInfo(e, t, ENUM_STREAM_SUB_CMD.liveEnd, e.publishStreamList[t].extra_info)
}

function resetHeartbeat(e) {
    e.logger.debug("rht.0 call"), clearTimeout(e.heartbeatTimer), e.heartbeatTimer = null, e.tryHeartbeatCount = 0, e.logger.debug("rht.0 call success")
}

function startHeartbeat(e) {
    if (e.logger.debug("sht.0 call"), e.runState === ENUM_RUN_STATE.login) {
        if (++e.tryHeartbeatCount > MAX_TRY_HEARTBEAT_COUNT) return e.logger.error("sht.0 come to try limit"), setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e), void e.onDisconnect(sdkErrorList.HEARTBEAT_TIMEOUT);
        e.logger.debug("sht.0 send packet");
        sendMessage(e, "hb", {
            reserve: 0
        }), e.heartbeatTimer = setTimeout(function () {
            startHeartbeat(e)
        }, e.heartbeatInterval), e.logger.debug("sht.0 call success")
    } else e.logger.info("sht.0 state error")
}

function resetTryLogin(e) {
    e.logger.debug("rtl.0 call"), clearTimeout(e.tryLoginTimer), e.tryLoginTimer = null, e.tryLoginCount = 0, e.logger.debug("rtl.0 call success")
}

function tryLogin(e) {
    if (e.logger.debug("tl.0 call"), e.runState === ENUM_RUN_STATE.trylogin) {
        if (++e.tryLoginCount > MAX_TRY_LOGIN_COUNT) {
            e.logger.error("tl.0 fail times limit");
            var t = e.lastRunState;
            return setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e), void(t == ENUM_RUN_STATE.login ? (e.logger.info("tl.0 fail and disconnect"), e.onDisconnect(sdkErrorList.LOGIN_DISCONNECT)) : (e.logger.info("tl.0 fail and callback user"), actionErrorCallback(e, "login")(sdkErrorList.LOGIN_TIMEOUT)))
        }
        if (e.websocket && 1 === e.websocket.readyState) {
            e.logger.info("tl.0 use current websocket and sent login");
            var s = loginBodyData(e);
            sendMessage(e, "login", s)
        } else {
            e.logger.debug("tl.0 need new websocket");
            try {
                e.websocket && (e.logger.info("tl.0 close error websocket"), e.websocket.onclose = null, e.websocket.onerror = null, e.websocket.close(), e.websocket = null), e.logger.debug("tl.0 new websocket"), e.websocket = new ZegoWebSocket(e.server), e.websocket.onopen = function () {
                    e.logger.info("tl.0 websocket.onpen call"), bindWebSocketHandler(e), e.logger.info("tl.0 websocket.onpen send login");
                    var t = loginBodyData(e);
                    sendMessage(e, "login", t), e.logger.debug("tl.0 websocket.onpen call success")
                }
            } catch (t) {
                e.logger.error("tl.0 websocket err:" + t)
            }
        }
        e.tryLoginTimer = setTimeout(function () {
            tryLogin(e)
        }, TRY_LOGIN_INTERVAL[e.tryLoginCount % MAX_TRY_LOGIN_COUNT]), e.logger.debug("tl.0 call success")
    } else e.logger.info("tl.0 state error")
}

function loginBodyData(e) {
    return {
        id_name: e.idName,
        nick_name: e.nickName,
        role: e.role,
        token: e.token,
        version: PROTO_VERSION,
        user_state_flag: e.userStateUpdate ? 1 : 0,
        room_create_flag: e.roomCreateFlag
    }
}

function resetRoom(e) {
    if (e.logger.debug("rr.0 call"), resetTryLogin(e), resetHeartbeat(e), resetCheckMessage(e), resetStreamCenter(e), e.streamList = [], e.publishStreamList = {}, e.streamQuerying = !1, e.joinLiveCallbackMap = {}, e.joinLiveRequestMap = {}, e.streamUrlMap = {}, resetBigRoomInfo(e), e.cmdCallback = {}, e.logger.debug("rr.0 call send logout=", e.sessionid), "0" !== e.sessionid) {
        sendMessage(e, "logout", {
            reserve: 0
        })
    }
    e.websocket && (e.websocket.onclose = null, e.websocket.onerror = null, e.websocket.close(), e.websocket = null), e.userid = "0", e.sessionid = "0", e.logger.setSessionInfo(e.appid, e.roomid, e.userid, e.idName, e.sessionid, PROTO_VERSION), e.logger.debug("rr.0 call success")
}

function fetchStreamList(e) {
    if (e.logger.debug("fsl.0 call"), e.runState === ENUM_RUN_STATE.login)
        if (e.streamQuerying) e.logger.info("fsl.0 already doing");
        else {
            e.streamQuerying = !0, e.logger.debug("fsl.0 send fetch request");
            sendMessage(e, "stream_info", {
                reserve: 0
            }), e.logger.debug("fsl.0 call success")
        } else e.logger.info("fsl.0 state error")
}

function fetchUserList(e) {
    e.logger.debug("ful.0 call"), e.userQuerying ? e.logger.info("ful.0 is already querying") : (e.userQuerying = !0, e.userTempList = [], fetchUserListWithPage(e, 0), e.logger.debug("ful.0 the first time call"))
}

function fetchUserListWithPage(e, t) {
    e.logger.debug("fulwp.0 call"), sendMessage(e, "user_list", {
        user_index: t,
        sort_type: 0
    }), e.logger.debug("fulwp.0 call success")
}

function isKeepTryLogin(e) {
    switch (e) {
        case 1002:
        case 1003:
            return !0;
        default:
            return !1
    }
}

function updateStreamInfo(e, t, s, r, o) {
    e.logger.debug("usi.0 call");
    var i = "";
    void 0 != r && "string" == typeof r && (i = r);
    var a = {
        stream_id: t,
        extra_info: i
    };
    sendMessage(e, "stream", {
        sub_cmd: s,
        stream_msg: JSON.stringify(a)
    }, void 0, o), e.logger.debug("usi.0 call success cmd " + s)
}

function sendSignalCmd(e, t, s, r, o, i) {
    (e.logger.debug("ssc.0 call"), e.runState === ENUM_RUN_STATE.login) ? (e.logger.debug("ssc.0 send signal cmd " + t), sendMessage(e, "signal", {
        sub_cmd: t,
        signal_msg: s,
        dest_id_name: [r]
    }, o, i), e.logger.debug("ssc.0 call success")) : e.logger.info("ssc.0 state error")
}

function getRequestId(e) {
    return ++e.cmdSeq, e.idName + "-" + e.cmdSeq
}

function getSignalCmdContent(e, t, s, r) {
    var o = {
        request_id: t,
        room_id: e.roomid,
        from_userid: e.idName,
        from_username: e.nickName,
        to_userid: s
    };
    return void 0 != r && (o.result = r), JSON.stringify(o)
}

function fetchReliableMessage(e, t, s) {
    e.logger.debug("frm.0 call"), sendMessage(e, "trans_fetch", {
        trans_type: t,
        trans_local_seq: s
    }), e.logger.debug("frm.0 call success")
}

function sendRelayMessageInternal(e, t, s, r, o) {
    e.logger.debug("srm.0 call"), sendMessage(e, "relay", {
        relay_type: t,
        relay_data: s
    }, r, o)
}

function setRelayTimer(e, t, s) {
    var r = generateRandumNumber(2 * s - ((new Date).getTime() + t) % s);
    e.logger.info("srt.0 setTimer " + r), e.relayTimer = setTimeout(function () {
        onRelayTimer(e)
    }, r)
}

function onRelayTimer(e) {
    if (0 != e.realyMessageList.length) {
        var t = e.realyMessageList[0];
        sendRelayMessageInternal(e, t.type, t.data, t.success, t.error), clearTimeout(e.relayTimer), e.relayTimer = null, e.realyMessageList.splice(0, 1), e.realyMessageList.length > 0 && setRelayTimer(e, e.serverTimeOffset, e.datiTimeWindow)
    } else e.logger.info("ort.0 no relay data")
}

function sendBigRoomMessageInternal(e, t, s, r) {
    e.logger.debug("sbim.0 call"), sendMessage(e, "bigim_chat", {
        msgs: t
    }, s, r)
}

function setBigImTimer(e, t, s) {
    var r = s - ((new Date).getTime() + t) % s,
        o = generateRandumNumber(s) + r;
    e.logger.info("sbt.0 setTimer " + o), e.bigImTimer = setTimeout(function () {
        onBigImTimer(e)
    }, o)
}

function onBigImTimer(e) {
    var t = (new Date).getTime() + e.serverTimeOffset;
    e.bigImLastTimeIndex = Math.floor(t / e.bigimTimeWindow);
    for (var s = [], r = [], o = 0; o < e.bigImMessageList.length && !(o >= 20); o++) {
        var i = e.bigImMessageList[o];
        s.push({
            msg_category: i.msg_category,
            msg_type: i.msg_type,
            msg_content: i.msg_content,
            bigmsg_client_id: i.bigmsg_client_id
        }), r.push(i.bigmsg_client_id)
    }
    e.bigImMessageList.length > 20 ? e.bigImMessageList.splice(0, 20) : e.bigImMessageList = [], sendBigRoomMessageInternal(e, s, handleBigImMsgRsp, function (t, s) {
        for (var o = 0; o < r.length; o++) {
            var i = r[o],
                a = e.bigImCallbackMap[i];
            a && (null != a.error && a.error(t, s), delete e.bigImCallbackMap[i])
        }
    }), clearTimeout(e.bigImTimer), e.bigImTimer = null, e.bigImMessageList.length > 0 && setBigImTimer(e, e.serverTimeOffset, e.bigimTimeWindow)
}

function generateRandumNumber(e) {
    return parseInt(Math.random() * (e + 1), 10)
}

function handleLoginFail(e, t) {
    if (e.logger.debug("hlf.0 call"), isKeepTryLogin(t.body.err_code)) e.logger.info("hlf.0 KeepTry true");
    else {
        var s = e.lastRunState;
        setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e);
        var r = getServerError(t.body.err_code);
        s == ENUM_RUN_STATE.login ? (e.logger.info("hlf.0 callback disconnect"), e.onDisconnect(r)) : (e.logger.info("hlf.0 callback error"), actionErrorCallback(e, "login")(r)), e.logger.debug("hlf.0 call success")
    }
}

function handleLoginSuccess(e, t) {
    e.logger.debug("hls.0 call");
    var s = e.lastRunState;
    if (setRunState(e, ENUM_RUN_STATE.login), e.userid = t.body.user_id, e.sessionid = t.body.session_id, e.logger.setSessionInfo(e.appid, e.roomid, e.userid, e.idName, e.sessionid, PROTO_VERSION), void 0 != t.body.config_info && (e.logger.setRemoteLogLevel(t.body.config_info.log_level), "" != t.body.config_info.log_url && e.logger.openLogServer(t.body.config_info.log_url)), void 0 != t.body.ret_timestamp && "string" == typeof t.body.ret_timestamp) {
        var r = parseFloat(t.body.ret_timestamp);
        e.serverTimeOffset = 0 == r ? 0 : t.body.ret_timestamp - (new Date).getTime()
    }
    if (void 0 != t.body.bigim_time_window && "number" == typeof t.body.bigim_time_window && (e.bigimTimeWindow = t.body.bigim_time_window), void 0 != t.body.dati_time_window && "number" == typeof t.body.dati_time_window && (e.datiTimeWindow = t.body.dati_time_window), resetTryLogin(e), resetHeartbeat(e), e.heartbeatInterval = t.body.hearbeat_interval, e.heartbeatInterval < MINIUM_HEARTBEAT_INTERVAL && (e.heartbeatInterval = MINIUM_HEARTBEAT_INTERVAL), e.heartbeatTimer = setTimeout(function () {
            startHeartbeat(e)
        }, e.heartbeatInterval), resetCheckMessage(e), e.sendDataCheckTimer = setTimeout(function () {
            startCheckMessageTimeout(e)
        }, e.sendDataCheckInterval), e.streamQuerying = !1, s == ENUM_RUN_STATE.login) e.logger.info("hls.0 recover from disconnect so call streamupdate"), handleFullUpdateStream(e, t.body.stream_seq, t.body.stream_info || []);
    else {
        e.logger.info("hls.0 success callback user"), e.streamList = t.body.stream_info || [], e.streamSeq = t.body.stream_seq;
        for (var o = 0; o < e.streamList.length; o++) e.streamList[o].anchor_id_name == e.idName && (updateStreamInfo(e, e.streamList[o].stream_id, ENUM_STREAM_SUB_CMD.liveEnd), e.streamList.splice(o, 1));
        var i;
        i = makeCallbackStreamList(e.streamList), actionSuccessCallback(e, "login")(i)
    }
    if (t.body.anchor_info) {
        var a = t.body.anchor_info.anchor_id_name,
            n = t.body.anchor_info.anchor_nick_name;
        e.onGetAnchorInfo(a, n)
    }
    e.logger.debug("hls.0 userStateUpdate " + e.userStateUpdate), e.userStateUpdate && (e.logger.info("hls.0 fetch all new userlist"), fetchUserList(e))
}

function handleLoginRsp(e, t) {
    if (e.logger.debug("hlr.0 call"), e.runState === ENUM_RUN_STATE.trylogin)
        if (t.header.seq === e.cmdSeq) {
            if (0 !== t.body.err_code) return handleLoginFail(e, t), void e.logger.info("hlr.0 server error=", t.body.err_code);
            handleLoginSuccess(e, t), e.logger.info("hlr.0 call success.")
        } else e.logger.info("hlr.0 in wrong seq, local=", e.cmdSeq, ",recv=", t.header.seq);
    else e.logger.info("hlr.0 state error")
}

function handleHeartbeatRsp(e, t) {
    if (e.logger.debug("hhbr.0 call"), 0 === t.body.err_code) {
        if (e.tryHeartbeatCount = 0, e.heartbeatInterval = t.body.hearbeat_interval, e.heartbeatInterval < MINIUM_HEARTBEAT_INTERVAL && (e.heartbeatInterval = MINIUM_HEARTBEAT_INTERVAL), void 0 != t.body.bigim_time_window && "number" == typeof t.body.bigim_time_window && (e.bigimTimeWindow = t.body.bigim_time_window), void 0 != t.body.dati_time_window && "number" == typeof t.body.dati_time_window && (e.datiTimeWindow = t.body.dati_time_window), void 0 != t.body.trans_seqs)
            for (var s = 0; s < t.body.trans_seqs.length; s++) {
                var r = t.body.trans_seqs[s].trans_type,
                    o = t.body.trans_seqs[s].trans_seq;
                if (!e.transSeqMap[r] || e.transSeqMap[r].seq !== o) {
                    var i = 0;
                    e.transSeqMap[r] ? (i = e.transSeqMap[r].seq, e.logger.debug("hhbr.0 type " + r + " old seq " + e.transSeqMap[r].seq + " server seq " + o)) : (i = 0, e.logger.debug("hhbr.0 type " + r + " server seq " + o)), fetchReliableMessage(e, r, i)
                }
            }
        for (var a in t.body.stream_seq !== e.streamSeq && (e.logger.debug("hhbr.0 current seq " + e.streamSeq + " server Seq " + t.body.stream_seq), fetchStreamList(e)), t.body.server_user_seq !== e.userSeq && e.userStateUpdate && (e.logger.info("hhbr.0 call update user " + t.body.server_user_seq, e.userSeq), fetchUserList(e)), e.publishStreamList) e.publishStreamList[a].state == ENUM_PUBLISH_STREAM_STATE.update_info && (e.logger.info("hbbr.0 try to update stream info"), updateStreamInfo(e, a, ENUM_STREAM_SUB_CMD.liveBegin, e.publishStreamList[a].extra_info));
        e.logger.debug("hhbr.0 call success")
    } else {
        e.logger.info("hhbr.0 call disconnect, server error=", t.body.err_code), setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e);
        var n = getServerError(t.body.err_code);
        e.onDisconnect(n)
    }
}

function handleLogoutRsp(e, t) {
    e.logger.debug("hlor.0 result=", t.body.err_code)
}

function handleSendCustomMsgRsp(e, t) {
    e.logger.debug("hscmr.0 call");
    var s, r = e.sendDataMap[t.header.seq];
    null != r ? ("custommsg" != (s = r._data).data.header.cmd ? e.logger.error("hscmr.0 cmd wrong" + s.data.header.cmd) : 0 === t.body.err_code ? null != s.success && s.success(t.header.seq, s.data.body.custom_msg) : null != s.error && s.error(getServerError(t.body.err_code), t.header.seq, s.data.body.custom_msg), delete e.sendDataMap[t.header.seq], e.sendDataList.remove(r)) : e.logger.error("hscmr.0 no found seq=" + t.header.seq), e.logger.debug("hscmr.0 call success")
}

function handleRelayRspCallback(e, t, s) {
    0 === t.body.err_code ? null != s.success && s.success(t.header.seq, t.body.relay_result) : null != s.error && s.error(getServerError(t.body.err_code), t.header.seq)
}

function handleBigImRspCallback(e, t, s) {
    0 === t.body.err_code ? null != s.success && handleBigImMsgRsp(e, t) : null != s.error && s.error(getServerError(t.body.err_code), t.header.seq)
}

function handleSendCommandMsgRsp(e, t) {
    e.logger.debug("hscmr.0 call");
    var s, r = e.sendCommandMap[t.header.seq];
    null != r && ("login" == (s = r._data).data.header.cmd ? e.logger.debug("hscmr.0 don't check " + s.data.header.cmd) : "relay" == s.data.header.cmd ? handleRelayRspCallback(e, t, s) : "bigim_chat" == s.data.header.cmd ? handleBigImRspCallback(e, t, s) : 0 === t.body.err_code ? null != s.success && s.success(t.header.seq) : null != s.error && s.error(getServerError(t.body.err_code), t.header.seq), delete e.sendCommandMap[t.header.seq], e.sendCommandList.remove(r)), e.logger.debug("hscmr.0 call success")
}

function handleSendRoomMsgRsp(e, t) {
    e.logger.debug("hsrmr.0 call");
    var s, r = e.sendDataMap[t.header.seq];
    null != r ? ("im_chat" != (s = r._data).data.header.cmd ? e.logger.error("hsrmr.0 cmd wrong" + s.data.header.cmd) : 0 === t.body.err_code ? s.success && s.success(t.header.seq, t.body.msg_id, s.data.body.msg_category, s.data.body.msg_type, s.data.body.msg_content) : s.error && s.error(getServerError(t.body.err_code), t.header.seq, s.data.body.msg_category, s.data.body.msg_type, s.data.body.msg_content), delete e.sendDataMap[t.header.seq], e.sendDataList.remove(r)) : e.logger.error("hsrmr.0 no found seq=" + t.header.seq), e.logger.debug("hsrmr.0 call success")
}

function handlePushCustomMsg(e, t) {
    var s = JSON.parse(t.body.custommsg);
    e.logger.debug("hpcm.0 submsg=", s), e.onRecvCustomCommand(s.from_userid, s.from_username, s.custom_content)
}

function handlePushRoomMsg(e, t) {
    e.onRecvRoomMsg(t.body.chat_data, t.body.server_msg_id, t.body.ret_msg_id)
}

function handleFullUpdateStream(e, t, s) {
    e.logger.debug("hfus.0 call"), e.streamSeq = t, e.logger.debug("hfus.0 server seq " + e.streamSeq), mergeStreamList(e, e.streamList, s, function (t, s, r) {
        0 !== t.length && (e.logger.debug("hfus.0 callback addstream"), e.onStreamUpdated(ENUM_STREAM_UPDATE_TYPE.added, makeCallbackStreamList(t))), 0 !== s.length && (e.logger.debug("hfus.0 callback delstream"), e.onStreamUpdated(ENUM_STREAM_UPDATE_TYPE.deleted, makeCallbackStreamList(s))), 0 !== r.length && (e.logger.debug("hfus.0 callback updatestream"), e.onStreamExtraInfoUpdated(makeCallbackStreamList(r)))
    }), e.logger.debug("hfus.0 call success")
}

function mergeStreamList(e, t, s, r) {
    e.logger.debug("msl.0 call");
    for (var o, i = [], a = [], n = [], l = 0; l < s.length; l++)
        if (s[l].anchor_id_name != e.idName) {
            o = !1;
            for (var g = 0; g < t.length; g++)
                if (s[l].stream_id === t[g].stream_id) {
                    s[l].extra_info !== t[g].extra_info && n.push(s[l]), o = !0;
                    break
                }
            o || i.push(s[l])
        } else e.logger.debug("msl.0 have self stream added");
    for (var d = 0; d < t.length; d++) {
        o = !1;
        for (var u = 0; u < s.length; u++)
            if (s[u].anchor_id_name != e.idName) {
                if (t[d].stream_id === s[u].stream_id) {
                    o = !0;
                    break
                }
            } else e.logger.debug("msl.0 have self stream deleted");
        o || a.push(t[d])
    }
    t = s, r(i, a, n), e.logger.debug("msl.0 call success")
}

function makeCallbackStreamList(e) {
    var t = [];
    if (void 0 != e && null != e)
        for (var s = 0; s < e.length; s++) t.push({
            anchor_id_name: e[s].anchor_id_name,
            stream_gid: e[s].stream_gid,
            anchor_nick_name: e[s].anchor_nick_name,
            extra_info: e[s].extra_info,
            stream_id: e[s].stream_id
        });
    return t
}

function handleFetchStreamListRsp(e, t) {
    e.logger.debug("hfslr.0 call"), e.streamQuerying = !1, 0 === t.body.err_code ? e.streamSeq !== t.body.stream_seq ? (handleFullUpdateStream(e, t.body.stream_seq, t.body.stream_info), e.logger.debug("hfslr.0 call success")) : e.logger.info("hfslr.0 same seq") : e.logger.info("hfslr.0 server error=", t.body.err_code)
}

function handleAddedStreamList(e, t) {
    e.logger.debug("hasl.0 call");
    for (var s, r = [], o = 0; o < t.length; o++)
        if (t[o].anchor_id_name != e.idName) {
            s = !1;
            for (var i = 0; i < e.streamList.length; i++)
                if (t[o].stream_id === e.streamList[i].stream_id) {
                    s = !0;
                    break
                }
            s || r.push(t[o])
        } else e.logger.debug("hdsl.0 have self stream added");
    if (0 !== r.length) {
        e.logger.debug("hasl.0 callback addstream");
        for (var a = 0; a < r.length; a++) e.streamList.push(r[a]);
        e.onStreamUpdated(ENUM_STREAM_UPDATE_TYPE.added, makeCallbackStreamList(r))
    }
    e.logger.debug("hasl.0 call success")
}

function handleDeletedStreamList(e, t) {
    e.logger.debug("hdsl.0 call");
    for (var s = [], r = 0; r < t.length; r++)
        if (t[r].anchor_id_name != e.idName) {
            for (var o = e.streamList.length - 1; o >= 0; o--)
                if (t[r].stream_id === e.streamList[o].stream_id) {
                    e.streamList.splice(o, 1), s.push(t[r]);
                    break
                }
        } else e.logger.debug("hdsl.0 have self stream deleted");
    0 !== s.length && (e.logger.debug("hdsl.0 callback delstream"), e.onStreamUpdated(ENUM_STREAM_UPDATE_TYPE.deleted, makeCallbackStreamList(s))), e.logger.debug("hdsl.0 call")
}

function handleUpdatedStreamList(e, t) {
    e.logger.debug("husl.0 call");
    for (var s = [], r = 0; r < t.length; r++)
        if (t[r].anchor_id_name != e.idName) {
            for (var o = 0; o < e.streamList.length; o++)
                if (t[r].stream_id === e.streamList[o].stream_id) {
                    t[r].extra_info !== e.streamList[o].extra_info && (e.streamList[o] = t[r], s.push(t[r]));
                    break
                }
        } else e.logger.debug("hsul.0 have self stream updated");
    0 !== s.length && (e.logger.debug("husl.0 callback updatestream"), e.onStreamExtraInfoUpdated(makeCallbackStreamList(s))), e.logger.debug("husl.0 call success")
}

function handlePushStreamUpdateMsg(e, t) {
    if (e.logger.debug("hpsum.0 call"), t.body.stream_info && 0 !== t.body.stream_info.length) {
        if (t.body.stream_info.length + e.streamSeq !== t.body.stream_seq) return e.logger.info("hpsum.0 call updatestream"), void fetchStreamList(e);
        switch (e.streamSeq = t.body.stream_seq, t.body.stream_cmd) {
            case ENUM_STREAM_UPDATE_CMD.added:
                handleAddedStreamList(e, t.body.stream_info);
                break;
            case ENUM_STREAM_UPDATE_CMD.deleted:
                handleDeletedStreamList(e, t.body.stream_info);
                break;
            case ENUM_STREAM_UPDATE_CMD.updated:
                handleUpdatedStreamList(e, t.body.stream_info)
        }
        e.logger.debug("hpsum.0 call success")
    } else e.logger.info("hpsum.0, emtpy list")
}

function handlePushKickout(e, t) {
    e.logger.info("hpk.0 call"), setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e);
    var s = {
        code: sdkErrorList.KICK_OUT.code,
        msg: sdkErrorList.KICK_OUT.msg + t.body.reason
    };
    e.onKickOut(s), e.logger.debug("hpk.0 call success")
}

function handlePushUserStateUpdateMsg(e, t) {
    if (e.logger.debug("hpus.0 call"), e.runState == ENUM_RUN_STATE.login)
        if (e.userStateUpdate) {
            if (e.userSeq + t.body.user_actions.length !== t.body.user_list_seq) return e.logger.info("hpus.0 fetch new userlist " + e.userSeq, NaN + t.body.user_list_seq), void fetchUserList(e);
            e.userSeq = t.body.user_list_seq, e.logger.debug("hpus.0 push userSeq " + e.userSeq);
            for (var s = [], r = 0; r < t.body.user_actions.length; r++) {
                var o = {
                    action: t.body.user_actions[r].Action,
                    idName: t.body.user_actions[r].IdName,
                    nickName: t.body.user_actions[r].NickName,
                    role: t.body.user_actions[r].Role,
                    loginTime: t.body.user_actions[r].LoginTime
                };
                s.push(o)
            }
            e.onUserStateUpdate(t.body.room_id, s), e.logger.debug("hpus.0 call success")
        } else e.logger.info("hpus.0 no userStateUpdate flag");
    else e.logger.info("hpus.0 not login")
}

function handleFetchUserListRsp(e, t) {
    if (e.logger.debug("hfulr.0 call"), 0 != t.body.err_code) return e.userQuerying = !1, void e.logger.info("hfulr.0 fetch error " + t.body.err_code);
    if (e.userStateUpdate) {
        e.userTempList.push.apply(e.userTempList, t.body.user_baseinfos);
        var s = t.body.ret_user_index;
        if (s != t.body.server_user_index) return e.logger.info("hfulr.0 fetch another page"), void fetchUserListWithPage(s + 1);
        e.userSeq = t.body.server_user_seq, e.logger.info("hfulr.0 set user Seq " + e.userSeq);
        for (var r = [], o = 0; o < e.userTempList.length; o++) {
            var i = {
                idName: e.userTempList[o].id_name,
                nickName: e.userTempList[o].nick_name,
                role: e.userTempList[o].role
            };
            r.push(i)
        }
        e.userQuerying = !1, e.onGetTotalUserList(e.roomid, r), e.userTempList = [], e.logger.debug("hfulr.0 call success user_list " + r + " count " + r.length)
    }
}

function handlePushSignalMsg(e, t) {
    if (e.runState == ENUM_RUN_STATE.login) {
        var s = JSON.parse(t.body.signal_msg);
        switch (e.logger.debug("hpcm.0 submsg= ", s), t.body.sub_cmd) {
            case ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveRequest:
                handlePushJoinLiveRequestMsg(e, s);
                break;
            case ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveResult:
                handlePushJoinLiveResultMsg(e, s);
                break;
            case ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveInvite:
                handlePushJoinLiveInviteMsg(e, s);
                break;
            case ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveStop:
                handlePushJoinLiveStopMsg(e, s)
        }
        e.logger.debug("hpsm.0 call end")
    } else e.logger.info("hpcm.0 not login")
}

function handlePushJoinLiveRequestMsg(e, t) {
    var s = t.request_id;
    if ("string" == typeof s) {
        var r = t.from_userid;
        "string" == typeof r ? (e.joinLiveRequestMap[s] = r, e.logger.info("hpjlrm.0 onRecvJoinLiveRequest " + r), e.onRecvJoinLiveRequest(s, t.from_userid, t.from_username, t.room_id)) : e.logger.error("hpjlrm.0 no from user")
    } else e.logger.error("hpjlrm.0 no requestId")
}

function handlePushJoinLiveInviteMsg(e, t) {
    var s = t.request_id;
    if ("string" == typeof s) {
        var r = t.from_userid;
        "string" == typeof r ? (e.joinLiveRequestMap[s] = r, e.logger.info("hpjlim.0 onRecvInviteJoinLiveRequest " + r), e.onRecvInviteJoinLiveRequest(s, t.from_userid, t.from_username, t.room_id)) : e.logger.error("hpjlim.0 no from user")
    } else e.logger.error("hpjlim.0 no requestId")
}

function handlePushJoinLiveResultMsg(e, t) {
    var s = t.request_id;
    if ("string" == typeof s) {
        var r = t.result;
        if (void 0 != r) {
            var o = 1 == r;
            if (e.joinLiveCallbackMap[s]) {
                var i = e.joinLiveCallbackMap[s];
                if (!i) return void e.logger.info("hpjlrm.o no callback");
                e.logger.info("hpjlrm.0 joinLiveRequest/invite result " + o), delete e.joinLiveCallbackMap[s], i(o, t.from_userid, t.from_username)
            }
        } else e.logger.info("hpjlrm.0 no result")
    } else e.logger.error("hpjlrm.0 no requestId")
}

function handlePushJoinLiveStopMsg(e, t) {
    var s = t.request_id;
    "string" == typeof s ? (e.logger.info("hpjlsm.0 onRecvEndJoinLiveCommand " + t.from_userid), e.onRecvEndJoinLiveCommand(s, t.from_userid, t.from_username, t.room_id)) : e.logger.error("hpjlsm.0 no requestId")
}

function handleStreamUpdateRsp(e, t) {
    if (e.runState == ENUM_RUN_STATE.login)
        if (0 == t.body.err_code) {
            e.logger.debug("hsur.0 stream seq " + e.streamSeq + " server seq " + t.body.stream_seq), e.streamSeq = t.body.stream_seq;
            for (var s = 0; s < t.body.stream_info.length; s++) {
                var r = t.body.stream_info[s].stream_id;
                if (!e.publishStreamList[r]) return void e.logger.info("hsur.0 stream is not exist");
                e.publishStreamList[r].state == ENUM_PUBLISH_STREAM_STATE.update_info && (e.publishStreamList[r].state = ENUM_PUBLISH_STREAM_STATE.publishing, e.onPublishStateUpdate(0, r, 0))
            }
        } else e.logger.info("hsur.0 stream update error " + t.body.err_code);
    else e.logger.info("hsur.0 not login")
}

function handleTransRsp(e, t) {
    if (e.runState == ENUM_RUN_STATE.login)
        if (0 == t.body.err_code) {
            var s = t.body.trans_type;
            e.transSeqMap[s] ? (e.transSeqMap[s].seq = t.body.trans_seq, e.logger.debug("htr.0 trans " + s + " seq " + t.body.trans_seq)) : e.logger.info("htr.0 cannot match send info")
        } else e.logger.info("htr.0 trans send error " + t.body.err_code);
    else e.logger.info("htr.0 not login")
}

function handleFetchTransRsp(e, t) {
    if (e.runState == ENUM_RUN_STATE.login)
        if (0 == t.body.err_code) {
            var s = t.body.trans_type,
                r = t.body.trans_seq;
            e.transSeqMap[s] ? e.transSeqMap[s].seq = r : e.transSeqMap[s] = {
                seq: r
            }, t.body.trans_user_idname != e.idName && e.onRecvReliableMessage(s, r, t.body.trans_data), e.logger.debug("hftr.0 trans " + s + " seq " + r)
        } else e.logger.info("hftr.0 trans send error " + t.body.err_code);
    else e.logger.info("hftr.0 not login")
}

function handlePushTransMsg(e, t) {
    if (e.runState == ENUM_RUN_STATE.login) {
        var s = t.body.trans_type,
            r = t.body.trans_seq;
        e.transSeqMap[s] ? e.transSeqMap[s].seq = r : e.transSeqMap[s] = {
            seq: r
        }, t.body.trans_user_idname != e.idName ? e.onRecvReliableMessage(s, r, t.body.trans_data) : e.logger.debug("hptr.0 receive self trans message"), e.logger.debug("hptr.0 trans " + s + " seq " + r)
    } else e.logger.info("hptr.0 not login")
}

function handlePushMergeMsg(e, t) {
    if (e.runState == ENUM_RUN_STATE.login) {
        for (var s = 0; s < t.body.messages.length; s++) 14001 === t.body.messages[s].sub_cmd && handlePushBigRooMsg(e, t.body.messages[s].msg_body);
        e.logger.debug("hpmm.0 call success")
    } else e.logger.info("hpmm.0 not login")
}

function handlePushBigRooMsg(e, t) {
    try {
        var s = JSON.parse(t)
    } catch (t) {
        return void e.logger.warn("hpbrm.0 parse json error")
    }
    if (void 0 != s) {
        for (var r = s.room_id, o = [], i = 0; i < s.msg_data.length; i++) {
            var a = s.msg_data[i];
            a.id_name != e.idName ? o.push({
                idName: a.id_name,
                nickName: a.nick_name,
                messageId: a.bigmsg_id,
                category: a.msg_category,
                type: a.msg_type,
                content: a.msg_content,
                time: a.send_time
            }) : e.logger.debug("hpbrm.0 self message")
        }
        0 == o.length ? e.logger.debug("hpbrm.0 no other pushData except self") : e.onRecvBigRoomMessage(o, r), e.logger.debug("hpbrm.0 call success")
    } else e.logger.warn("hpbrm.0 cann't find message body")
}

function handleBigImMsgRsp(e, t) {
    if (e.runState == ENUM_RUN_STATE.login) {
        e.bigimTimeWindow != t.body.bigim_time_window && (e.bigimTimeWindow = t.body.bigim_time_window);
        for (var s = 0; s < t.body.msgs.length; s++) {
            var r = t.body.msgs[s].bigmsg_client_id,
                o = t.body.msgs[s].bigmsg_id;
            if (e.bigImCallbackMap[r]) {
                var i = e.bigImCallbackMap[r].success;
                null != i && i(t.header.seq, o), delete e.bigImCallbackMap[r]
            }
        }
    } else e.logger.info("hbmr.0 not login")
}

function bindWebSocketHandler(e) {
    e.websocket.onmessage = function (t) {
        var s = JSON.parse(t.data);
        if (e.logger.debug("jsonmsg= ", s.header.cmd), "login" !== s.header.cmd)
            if (s.header.appid === e.appid && s.header.session_id === e.sessionid && s.header.user_id === e.userid && s.header.room_id === e.roomid && e.runState === ENUM_RUN_STATE.login) switch (handleSendCommandMsgRsp(e, s), s.header.cmd) {
                case "hb":
                    handleHeartbeatRsp(e, s);
                    break;
                case "logout":
                    handleLogoutRsp(e, s);
                    break;
                case "custommsg":
                    handleSendCustomMsgRsp(e, s);
                    break;
                case "stream_info":
                    handleFetchStreamListRsp(e, s);
                    break;
                case "push_custommsg":
                    handlePushCustomMsg(e, s);
                    break;
                case "push_stream_update":
                    handlePushStreamUpdateMsg(e, s);
                    break;
                case "push_kickout":
                    handlePushKickout(e, s);
                    break;
                case "stream_url":
                    handleFetchStreamUrlRsp(e, s);
                    break;
                case "stream_publish":
                    handleFetchStreamPublishUrlRsp(e, s);
                    break;
                case "webrtc_url":
                    break;
                case "im_chat":
                    handleSendRoomMsgRsp(e, s);
                    break;
                case "push_im_chat":
                    handlePushRoomMsg(e, s);
                    break;
                case "push_userlist_update":
                    handlePushUserStateUpdateMsg(e, s);
                    break;
                case "user_list":
                    handleFetchUserListRsp(e, s);
                    break;
                case "push_signal":
                    handlePushSignalMsg(e, s);
                    break;
                case "stream":
                    handleStreamUpdateRsp(e, s);
                    break;
                case "trans":
                    handleTransRsp(e, s);
                    break;
                case "trans_fetch":
                    handleFetchTransRsp(e, s);
                    break;
                case "push_trans":
                    handlePushTransMsg(e, s);
                    break;
                case "push_merge_message":
                    handlePushMergeMsg(e, s)
            } else e.logger.info("ws.bwsh.0 check session fail.");
        else handleLoginRsp(e, s)
    }, e.websocket.onclose = function (t) {
        e.logger.info("ws.oc.0 msg=" + JSON.stringify(t)), e.runState !== ENUM_RUN_STATE.logout ? e.runState === ENUM_RUN_STATE.trylogin && e.tryLoginCount <= MAX_TRY_LOGIN_COUNT ? e.logger.info("ws.oc.0 is called because of try login") : e.runState === ENUM_RUN_STATE.login ? (e.logger.info("ws.oc.0 is called because of network broken, try again"), setRunState(e, ENUM_RUN_STATE.trylogin), resetTryLogin(e), tryLogin(e)) : (e.logger.info("ws.oc.0 out of think!!!"), setRunState(e, ENUM_RUN_STATE.logout), resetRoom(e), e.onDisconnect(sdkErrorList.UNKNOWN)) : e.logger.info("ws.oc.0 onclose logout flow call websocket.close")
    }, e.websocket.onerror = function (t) {
        e.logger.info("ws.oe.0 msg=" + JSON.stringify(t))
    }
}
for (var registerNotifyList = ["onDisconnect", "onKickOut", "onRecvCustomCommand", "onStreamUpdated", "onStreamExtraInfoUpdated", "onPlayStateUpdate", "onRecvRoomMsg", "onUserStateUpdate", "onGetTotalUserList", "onPublishStateUpdate", "onRecvJoinLiveRequest", "onRecvInviteJoinLiveRequest", "onRecvEndJoinLiveCommand", "onStreamUrlUpdate", "onGetAnchorInfo", "onPublishQualityUpdate", "onPlayQualityUpdate", "onRecvReliableMessage", "onRecvBigRoomMessage", "onVideoSizeChanged"], i = 0; i < registerNotifyList.length; i++) ZegoClient.prototype[registerNotifyList[i]] = function () {
};
module.exports.ZegoClient = ZegoClient;